import { ScreenSpaceEventHandler, ScreenSpaceEventType } from 'cesium'

// 鼠标左键单击事件
const mouseLeftClick = (viewer, func) => {
  const handler = new ScreenSpaceEventHandler(viewer.canvas)
  handler.setInputAction(func, ScreenSpaceEventType.LEFT_CLICK)
}

// 鼠标左键双击事件
const mouseLeftDoubleClick = (viewer, func) => {
  const handler = new ScreenSpaceEventHandler(viewer.canvas)
  handler.setInputAction(func, ScreenSpaceEventType.LEFT_DOUBLE_CLICK)
}

// 鼠标右键单击事件
const mouseRightClick = (viewer, func) => {
  const handler = new ScreenSpaceEventHandler(viewer.canvas)
  handler.setInputAction(func, ScreenSpaceEventType.RIGHT_CLICK)
}

// 鼠标移动事件
const mouseMove = (viewer, func) => {
  const handler = new ScreenSpaceEventHandler(viewer.canvas)
  handler.setInputAction(func, ScreenSpaceEventType.MOUSE_MOVE)
}

// 禁用实体双击追踪
const disableTrackedEntity = viewer => {
  // 获取Viewer的内部ScreenSpaceEventHandler
  var screenSpaceEventHandler = viewer.cesiumWidget.screenSpaceEventHandler

  // 移除原有的双击事件处理器
  screenSpaceEventHandler.removeInputAction(
    ScreenSpaceEventType.LEFT_DOUBLE_CLICK
  )

  // 或者，如果你只想移除针对特定实体的双击追踪，可以这样：
  // viewer.trackedEntity = undefined; // 清空当前正在追踪的实体

  // 如果你还需要完全禁用所有实体的双击交互，可以进一步自定义事件处理逻辑：
  // screenSpaceEventHandler.setInputAction(function(movement) {
  // 在这里你可以添加自己的逻辑或者不做任何事情以忽略双击事件
  // }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
}

export {
  mouseLeftClick,
  mouseLeftDoubleClick,
  mouseRightClick,
  mouseMove,
  disableTrackedEntity
}
